<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Unity基础-2D相机渲染到RT的相关设置 | NoGameNoLife</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="2D相机渲染到RT的相关设置1. ClearFlag的设置在完成一些Shader效果的时候，我们有时候会使用多个相机用于渲染，例如：在流水Shader中，我们会使用一个专门的相机渲染圆形Sprite，并将其渲染到RenderTexture上，然后对RT进行后处理来达到流水效果。当相机需要渲染到RT上时，相机的ClearFlags属性设置就至关重要。 ClearFlags这个属性指的是相机在渲染图像">
<meta property="og:type" content="article">
<meta property="og:title" content="Unity基础-2D相机渲染到RT的相关设置">
<meta property="og:url" content="http://example.com/2021/02/23/Unity%E5%9F%BA%E7%A1%80-2D%E7%9B%B8%E6%9C%BA%E6%B8%B2%E6%9F%93%E5%88%B0RT%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE/index.html">
<meta property="og:site_name" content="NoGameNoLife">
<meta property="og:description" content="2D相机渲染到RT的相关设置1. ClearFlag的设置在完成一些Shader效果的时候，我们有时候会使用多个相机用于渲染，例如：在流水Shader中，我们会使用一个专门的相机渲染圆形Sprite，并将其渲染到RenderTexture上，然后对RT进行后处理来达到流水效果。当相机需要渲染到RT上时，相机的ClearFlags属性设置就至关重要。 ClearFlags这个属性指的是相机在渲染图像">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="e:/GiteeBlog/source_posts/2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets/Depth.gif">
<meta property="og:image" content="e:/GiteeBlog/source_posts/2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets/DepthOnly与DontClear(2)_1.gif">
<meta property="og:image" content="e:/GiteeBlog/source_posts/2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets/ColorAlpha.gif">
<meta property="article:published_time" content="2021-02-23T02:07:59.000Z">
<meta property="article:modified_time" content="2021-02-23T14:37:21.960Z">
<meta property="article:author" content="林文豪">
<meta property="article:tag" content="2D相机设置">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="e:/GiteeBlog/source_posts/2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets/Depth.gif">
  
    <link rel="alternate" href="/atom.xml" title="NoGameNoLife" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/css/style.css">

<meta name="generator" content="Hexo 5.1.1"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">NoGameNoLife</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://example.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Unity基础-2D相机渲染到RT的相关设置" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2021/02/23/Unity%E5%9F%BA%E7%A1%80-2D%E7%9B%B8%E6%9C%BA%E6%B8%B2%E6%9F%93%E5%88%B0RT%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE/" class="article-date">
  <time datetime="2021-02-23T02:07:59.000Z" itemprop="datePublished">2021-02-23</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Unity%E5%9F%BA%E7%A1%80/">Unity基础</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Unity基础-2D相机渲染到RT的相关设置
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="2D相机渲染到RT的相关设置"><a href="#2D相机渲染到RT的相关设置" class="headerlink" title="2D相机渲染到RT的相关设置"></a>2D相机渲染到RT的相关设置</h3><h4 id="1-ClearFlag的设置"><a href="#1-ClearFlag的设置" class="headerlink" title="1. ClearFlag的设置"></a>1. ClearFlag的设置</h4><p>在完成一些Shader效果的时候，我们有时候会使用多个相机用于渲染，例如：在流水Shader中，我们会使用一个专门的相机渲染圆形Sprite，并将其渲染到RenderTexture上，然后对RT进行后处理来达到流水效果。当相机需要渲染到RT上时，相机的ClearFlags属性设置就至关重要。</p>
<p>ClearFlags这个属性指的是相机在渲染图像的时候，空白区域的缓存用什么来清理。ClearFlags有四个选项，Skybox、SolidColor、DepthOnly、DontClear。Skybox和SolidColor很好理解，就是用天空盒和固定的颜色来清理空白区域；DepthOnly会先寻找那些ClearFlags也是DepthOnly的相机，然后将这些相机根据相机属性中的Depth值从大到小排序，然后依次对当前相机的空白区域进行清理。由此也造成了一个现象，对于设置为DepthOnly的相机来说，如果相机中的物体移动了， 那么该相机之前的颜色信息是不会被清理的，所呈现的效果与DontClear相同；DontClear不会清理相机的颜色信息。</p>
<p>Clear这个单词在前两个选项中可以被理解为填充，但是对于后两个选项来说理解为清理比较容易理解。</p>
<p><img src="E:\GiteeBlog\source_posts\2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets\Depth.gif" alt="Depth"></p>
<p><img src="E:\GiteeBlog\source_posts\2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets\DepthOnly与DontClear(2)_1.gif" alt="DepthOnly与DontClear(2)_1"></p>
<p><img src="E:\GiteeBlog\source_posts\2021-02-23-Unity基础-2D相机渲染到RT的相关设置.assets\ColorAlpha.gif" alt="ColorAlpha"></p>
<h4 id="2-Background的设置"><a href="#2-Background的设置" class="headerlink" title="2. Background的设置"></a>2. Background的设置</h4><p>当相机的ClearFlag设置为SolidColor时，在必要情况下我们需要谨慎地设置Background的颜色属性。例如：在进行模糊操作后，我们也许会用到像素的透明度对图像进行后处理操作，这时我们需要将Background中颜色的透明度设置为0，使得图像的空白部分对后处理操作没有任何影响。</p>
<h4 id="3-Projection的设置"><a href="#3-Projection的设置" class="headerlink" title="3. Projection的设置"></a>3. Projection的设置</h4><p>此选项设置为Orthographic即可。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://example.com/2021/02/23/Unity%E5%9F%BA%E7%A1%80-2D%E7%9B%B8%E6%9C%BA%E6%B8%B2%E6%9F%93%E5%88%B0RT%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE/" data-id="ckljgxjog000078dl0here7mh" class="article-share-link">分享</a>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/2D%E7%9B%B8%E6%9C%BA%E8%AE%BE%E7%BD%AE/" rel="tag">2D相机设置</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/02/24/Unity-Mesh-%E7%BB%98%E5%88%B6%E6%AD%A3%E6%96%B9%E4%BD%93/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Unity-Mesh-绘制正方体
        
      </div>
    </a>
  
  
    <a href="/2021/02/22/Shader-2D-%E6%B5%81%E6%B0%B4%E6%95%88%E6%9E%9C/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Shader-2D-流水效果</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Shader/">-Shader</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Artifical-Intelligence/">Artifical Intelligence</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Artifical-Intelligence/NPC-Behavior-Decision-making/">NPC Behavior Decision-making</a><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Artifical-Intelligence/NPC-Behavior-Decision-making/GOAP/">GOAP</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Artifical-Intelligence/NPC-Behavior-Decision-making/Utility-based-System/">Utility-based System</a></li></ul></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Shader/">Shader</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Unity-Mesh/">Unity-Mesh</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Unity%E5%9F%BA%E7%A1%80/">Unity基础</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Shader/" rel="tag">-Shader</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/2D%E7%9B%B8%E6%9C%BA%E8%AE%BE%E7%BD%AE/" rel="tag">2D相机设置</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Artifical-Intelligence/" rel="tag">Artifical Intelligence</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GOAP/" rel="tag">GOAP</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Unity-Mesh/" rel="tag">Unity-Mesh</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Utility-based-System/" rel="tag">Utility-based System</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E2%80%94-Shader/" rel="tag">— Shader</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/Shader/" style="font-size: 10px;">-Shader</a> <a href="/tags/2D%E7%9B%B8%E6%9C%BA%E8%AE%BE%E7%BD%AE/" style="font-size: 10px;">2D相机设置</a> <a href="/tags/Artifical-Intelligence/" style="font-size: 20px;">Artifical Intelligence</a> <a href="/tags/GOAP/" style="font-size: 15px;">GOAP</a> <a href="/tags/Unity-Mesh/" style="font-size: 10px;">Unity-Mesh</a> <a href="/tags/Utility-based-System/" style="font-size: 10px;">Utility-based System</a> <a href="/tags/%E2%80%94-Shader/" style="font-size: 10px;">— Shader</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/02/">二月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/01/">一月 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/12/">十二月 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/02/24/Unity-Mesh-%E7%BB%98%E5%88%B6%E6%AD%A3%E6%96%B9%E4%BD%93/">Unity-Mesh-绘制正方体</a>
          </li>
        
          <li>
            <a href="/2021/02/23/Unity%E5%9F%BA%E7%A1%80-2D%E7%9B%B8%E6%9C%BA%E6%B8%B2%E6%9F%93%E5%88%B0RT%E7%9A%84%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE/">Unity基础-2D相机渲染到RT的相关设置</a>
          </li>
        
          <li>
            <a href="/2021/02/22/Shader-2D-%E6%B5%81%E6%B0%B4%E6%95%88%E6%9E%9C/">Shader-2D-流水效果</a>
          </li>
        
          <li>
            <a href="/2021/01/30/%E5%AD%A6%E4%B9%A0Shader%E5%85%A5%E9%97%A8%E7%B2%BE%E8%A6%81%E7%9A%84%E8%AE%B0%E5%BD%95/">学习Shader入门精要的记录</a>
          </li>
        
          <li>
            <a href="/2020/12/29/%E4%B8%AA%E4%BA%BA%E5%AF%B9Utility-based-System%E7%90%86%E8%A7%A3/">个人对Utility-based System的理解</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2021 林文豪<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/fancybox/jquery.fancybox.css">

  
<script src="/fancybox/jquery.fancybox.pack.js"></script>




<script src="/js/script.js"></script>




  </div>
</body>
</html>